import 'package:bitcoin_mine/controllers/animation_controller.dart'
    as balance_animation;
import 'package:bitcoin_mine/widgets/btc_usd_chart.dart';
import 'package:bitcoin_mine/widgets/rolling_number_units.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../controllers/wallet_controller.dart';
import '../l10n/app_localizations.dart';

class BalanceCard extends StatelessWidget {
  const BalanceCard({super.key});

  @override
  Widget build(BuildContext context) {
    final WalletController walletController = Get.find();
    final balance_animation.BalanceAnimationController controller =
        Get.find<balance_animation.BalanceAnimationController>();
    final l10n = AppLocalizations.of(context);

    return Container(
      width: double.infinity,
      margin: EdgeInsets.symmetric(horizontal: 16.w, vertical: 8.h),
      padding: EdgeInsets.only(top: 20.h),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
          colors: [const Color(0xFF00287E), const Color(0xFF05FFFD)],
        ),
        borderRadius: BorderRadius.circular(12.r),
        border: Border.all(color: const Color(0xFF05FFFD), width: 1.5.r),
      ),
      child: Column(
        children: [
          // 余额标题
          Text(
            l10n.balanceLabel,
            style: TextStyle(
              color: Colors.white70,
              fontSize: 20.sp,
              fontWeight: FontWeight.w500,
            ),
          ),

          SizedBox(height: 8.h),

          // 余额金额
          Obx(
            () => RollingNumberUnits(
              units: controller.displayBalanceUnits.value,
              scale: 15,
              prefix: '',
              suffix: ' btc',
              duration: const Duration(milliseconds: 800),
              style: TextStyle(color: Colors.white, fontSize: 24.sp),
            ),
          ),

          SizedBox(height: 20.h),

          Stack(
            children: [
              // BTC/USD图表组件
              const BtcUsdChart(),
              Align(
                alignment: Alignment.topCenter,
                child: // 提现按钮
                    GestureDetector(
                  onTap: walletController.withdraw,
                  child: Container(
                    width: 154.w,
                    height: 50.h,
                    decoration: BoxDecoration(
                      image: DecorationImage(
                        image: AssetImage("assets/images/btn_invite_now.png"),
                        fit: BoxFit.fill,
                      ),
                    ),
                    child: Center(
                      child: Text(
                        l10n.withdrawButton,
                        style: TextStyle(
                          color: const Color(0xFFFFFFFF),
                          fontSize: 20.sp,
                          fontWeight: FontWeight.w600,
                        ),
                      ),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
